Day 12 - Regular expressions - Single

characters

Solutions to exercises

Exercise 12.01

Match “dog”, “Dog”, and “hog” into examples.txt

Solution

$ grep -E ".og" examples.txt

dog

Dug the Dog

dog

corn dog

hogwash

wild hog

hog

Go back to the exercise

Exercise 12.02

Log entries in the file simple.log contain the string HTTP/<version> <code>, where <version> is

the version of the HTTP protocol in use (either 1.0 or 1.1) and <code>“ is the three-digits

HTTP request status code. Extract all lines with a status “4xx” (that is a status between 400 and 499).

Count how often each status occurs.

Solution

The HTTP/1.0 or HTTP/1.1 strings can be used as anchors to identify the three digits we are interested

in, but then we want to get rid of them to aggregate the HTTP status codes only